<?php

namespace app\services;

use app\model\CustomerInfo;
use app\model\tmp\LiAllData;
use app\model\tmp\LiBc;
use app\model\tmp\LiBcDataModel;
use app\model\tmp\LiTmp;
use app\model\tmp\LiTmpData;

class DealDataService
{
    /**
     *
     * @return string[]
     */
    public static function dealData()
    {
        return ['status' => 'ok'];
        try {
            $model = new LiTmp();
            $data = $model->where([['id', '>', 29999]])->select()->toArray();
            //return ['status' => 'ok'];
            $dx = $yd = $lt = [];
            foreach ($data as $val) {
                $pattern = '/^1(33|53|7[37]|8[019]|9[139])\d{8}$|^162\d{8}$|^170[012]\d{7}$|^190\d{8}$/';
                if (preg_match($pattern, $val['bb'])) {
                    $dx[] = $val['bb'];
                }
            }

            $model->where([['bb', 'in', $dx]])->update(['is_deal' => '电信']);
        } catch (\Exception $e) {
            logData($e->getMessage());
        }
        return ['status' => 'ok'];
    }

    public static function dealBcData()
    {
        return ['status' => 'ok'];
        try {
            $model = new LiBcDataModel();
            $bcData = $model->select()->toArray();
            $customerModel = new CustomerInfo();
            $ids = [];
            foreach ($bcData as $val) {
                if ($customerModel->where(['mobile' => $val['bb']])->count('id') != 0) {
                    $ids[] = $val['id'];
                }
            }
            $model->where([['id', 'in', $ids]])->update(['is_exist' => 2]);
        } catch (\Exception $e) {
            logData($e->getMessage() . $e->getTraceAsString());
        }

        return ['status' => 'ok'];
    }

    public static function dealBcWaitData()
    {
        return ['status' => 'ok'];
        $bcData = (new LiTmpData())->select()->toArray();
        $model = new CustomerInfo();
        $data = [];
        foreach ($bcData as $val) {
            if ($model->where(['mobile' => $val['bb']])->count('id') != 0) {
                continue;
            }
            $data[] = [
                'username' => $val['aa'],
                'mobile' => $val['bb'],
                'organization_name' => $val['cc'],
                'organization_quality' => '国企',
                'user_area' => '',
                'communicate_records' => '同事客户' . $val['hh'],
                'next_time' => '2025-09-15',
                'visit_status' => '未到访',
                'customer_source' => '白名单',
                'customer_type' => 2,
                'accumulation_fund' => $val['ee'] . ' ' . $val['ff'] . '% ' . $val['gg'],
            ];
        }
        $model->insertAll($data);
        return ['status' => 'ok'];
    }
}